package com.sx.feesunit.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ModelDriven;
import com.sx.core.BaseAction;
import com.sx.core.ChartEntity;
import com.sx.feesunit.biz.IAreaBiz;
import com.sx.feesunit.entity.AreaEntity;
import com.sx.feesunit.exception.SXException;

@SuppressWarnings("serial")
public class AnalyseAction extends BaseAction implements ModelDriven<AreaEntity> {
	private IAreaBiz iareabiz;
	private AreaEntity area = new AreaEntity();
	private Log log = LogFactory.getLog(this.getClass());
	/**
	 *分析小区的住户数量 
	 **/
	public void getTop10AreaOwedData() throws Exception{
		try {
			List<AreaEntity> list = iareabiz.findTop10AreaUsers(area);
			ChartEntity chart = new ChartEntity();
			chart.setCaption("小区用户数量前10名");
			chart.setData(list);
			chart.setFormatnumberscale("0");
//			chart.setNumberprefix("个");
			chart.setXaxisname("小区名称");
			chart.setYaxisname("用户数量");
			String jsonobject = JSONObject.toJSONString(chart);
			/*String data = JSONArray.toJSONString(list);
			String jsonobject = "{\"chart\":{\"formatnumberscale\":\"0\",\"showborder\":\"1\",\"caption\":\"Yearly Sales\",\"xaxisname\":\"Year\",\"yaxisname\":\"Sales\"},\"data\":"+data+"}";
	*/		outJsonString(jsonobject);
		} catch (Exception e) {
			outJsonString("{}");
			log.error("分析小区的住户数量",e);
			throw new SXException(e);
			// TODO: handle exception
		}
		
		
	}
	/**
	 * @return the iareabiz
	 */
	public IAreaBiz getIareabiz() {
		return iareabiz;
	}
	/**
	 * @param iareabiz the iareabiz to set
	 */
	public void setIareabiz(IAreaBiz iareabiz) {
		this.iareabiz = iareabiz;
	}
	public AreaEntity getModel() {
		// TODO Auto-generated method stub
		return area;
	}
	
}
